package com.qiaofang.dataprocessing.service.impl;

import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.common.page.PageUtil;
import com.qiaofang.dataprocessing.dao.PropertyEntrustDao;
import com.qiaofang.dataprocessing.service.PropertyEntrustService;
import com.qiaofang.dataprocessing.stub.bean.PageCustomizeDTO;
import com.qiaofang.dataprocessing.stub.bean.request.PropertyEntrustRequest;
import com.qiaofang.dataprocessing.stub.bean.response.PropertyEntrustDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: youqing.yang
 * @Create: 2020/12/15 16:14
 * @Description:
 **/
@Service
@Slf4j
public class PropertyEntrustServiceImpl implements PropertyEntrustService {

    @Autowired
    private PropertyEntrustDao propertyEntrustDao;

    @Override
    public PageCustomizeDTO<PropertyEntrustDTO> getPropertyEntrustPage(PropertyEntrustRequest propertyEntrustRequest, PageDTO page) {
        PageCustomizeDTO<PropertyEntrustDTO> pageResultDTO = new PageCustomizeDTO<>();
        Long count = propertyEntrustDao.getPropertyEntrustCount(propertyEntrustRequest);
        List<PropertyEntrustDTO> propertyEntrustList = new ArrayList<>();
        if (count > 0) {
            propertyEntrustList = propertyEntrustDao.getPropertyEntrustPage(propertyEntrustRequest, PageUtil.getRowBounds(page));
        }
        pageResultDTO.setCount(count);
        pageResultDTO.setItems(propertyEntrustList);
        return pageResultDTO;
    }

    @Override
    public Integer acceptEntrustMyself(Long propertyEntrustId) {
        return propertyEntrustDao.acceptEntrustMyself(propertyEntrustId);
    }
}
